
package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.PushFailedLoger;
import com.ruoyi.system.entity.PushInfo;
import com.ruoyi.system.mapper.PushFailedLogerMapper;
import com.ruoyi.system.mapper.PushInfoMapper;
import com.ruoyi.system.service.PushFailedLogerService;
//import com.ruoyi.system.services.PushFailedLogerServices;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * (PushFailedLoger)表服务实现类
 *
 * @author makejava
 * @since 2023-05-31 16:46:22
 */
@Service("pushFailedLogerService")
public class PushFailedLogerServiceImpl implements PushFailedLogerService {

    @Resource
    private PushFailedLogerMapper pushFailedLogerMapper;

    @Resource
    private PushInfoMapper pushInfoMapper;

//    @Resource
//    private PushFailedLogerServices pushFailedLogerServices;

    /**
     * 新增数据
     *
     * @return 实例对象
     */
    @Scheduled(cron = "0 0 */3 * * ?")
    public void insert() {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 减去3个小时
        LocalDateTime threeHoursAgo = now.minusHours(3);
        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 格式化输出时间
        String formattedDateTime = threeHoursAgo.format(formatter);

        List<PushInfo> pushInfos =  pushInfoMapper.selectByTime(now.format(formatter),formattedDateTime);

        if(pushInfos == null || pushInfos.size() == 0) {
            return ;
        }
        for (PushInfo pushInfo : pushInfos) {
            PushFailedLoger pushFailedLoger = null;
//            pushFailedLogerServices.createushFailedLoger(pushInfo.getPushInfo());
            pushFailedLoger.setPushRequestTime(pushInfo.getCreateTime());
            this.pushFailedLogerMapper.insert(pushFailedLoger);
        }

    }

    /**
     * 分页查询
     *
     * @param pushFailedLoger 筛选条件
     * @return 查询结果
     */
    @Override
    public List<PushFailedLoger> queryByPage(PushFailedLoger pushFailedLoger) {
        return this.pushFailedLogerMapper.queryAllByLimit(pushFailedLoger);
    }
}
